home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2510.ZIP / TRSOURCE.EXE / STREET.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  3KB  |  94 lines

  1. /*********
  2. *  Function: STREET
  3. *  by Tom Rettig, Leonard Zerman
  4. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  5. *
  6. *  Syntax: STREET( <expC> )
  7. *  Return: <expC> street name from street address string
  8. *  Note  : Return string is same length as <expC>.
  9. *          Fails on:
  10. *             One Snobby Court    (use 1 Snobby Court)
  11. *             123 1/2 31st Street (use 123-1/2 31st Street)
  12. *             123 N.E. Central Ave. (use Central Ave. N.E.)
  13. *             69th Street & Main (use Main & 69th Street)
  14. *             69th Street & 34th (spell out first street name)
  15. *********/
  16.  
  17. #include "trlib.h"
  18.  
  19. TRTYPE street()
  20. {
  21.    static char *direction[] = { "NORTH ", "SOUTH ", "EAST ", "WEST " };
  22.    static char funcname[] = { "street" };
  23.    char *instr, *start, *outbuffer;
  24.    int i, j, strlen;
  25.    int found = FALSE;
  26.  
  27.    if ( PCOUNT==1 && ISCHAR(1) )
  28.    {
  29.       instr = start = _parc(1);               /* get parameter */
  30.       strlen = _tr_strlen( instr );           /* get lenth of string */
  31.       
  32.       outbuffer = _tr_allocmem( (unsigned)strlen+1); /* allocate return buffer */
  33.       
  34.       if (!(outbuffer))                       /* if error on allocation */
  35.          {
  36.             _retc(instr);                     /* return original string */
  37.             return;
  38.          }
  39.          
  40.       while ( *instr==SPACEC )                /* skip leading spaces */
  41.          instr++;
  42.  
  43.       /* if first char is a digit, skip to next space */
  44.       /* fails if address is a word; e.g.: One Snobby Court */
  45.       if ( ISDIGIT(*instr) )
  46.       {
  47.          while ( *instr != SPACEC && *instr )
  48.             instr++;
  49.       }
  50.  
  51.       /* skip any extra spaces after leading 'digitword' */
  52.       /* digitword could be 1234-A or 123-1/2 */
  53.       while ( *instr==SPACEC )
  54.          instr++;
  55.  
  56.       /* skip N/S/E/W direction */
  57.       for ( i=0; i<4; i++ )
  58.       {
  59.          for ( j=0; instr[j]==direction[i][j] ||
  60.                     instr[j]-UPPER==direction[i][j] ||
  61.                    (instr[j]==ABRENDCHAR && (j==1||j==2)); j++ )
  62.          {
  63.             /* if both end with space or instr is one or two letter abbre */
  64.             if ( instr[j]==SPACEC || instr[j]==ABRENDCHAR )
  65.             {
  66.                instr += ++j;
  67.                found = TRUE;
  68.                break;
  69.             }
  70.          }
  71.          if ( found )
  72.             break;
  73.       }
  74.          
  75.       /* skip any extra spaces after direction */
  76.       while ( *instr==SPACEC )
  77.          instr++;
  78.  
  79.       _tr_strcpy( outbuffer, instr );           /* copy to output buff */
  80.  
  81.       for (i=_tr_strlen(outbuffer), j=0; i<strlen; i++, j++)
  82.            outbuffer[i] = start[j];          /* pad to original length */
  83.  
  84.       outbuffer[i] = NULLC;                         /* null terminator */
  85.  
  86.       _tr_toup(outbuffer);                  /* uppercase return string */
  87.       _retc(outbuffer);                    /* return balance of string */
  88.       _tr_freemem(outbuffer,(unsigned)strlen+1); 
  89.    }
  90.    else
  91.       _retc( _tr_errmsgs( funcname, E_SYNTAX ));       /* syntax error */
  92. }
  93.  
  94.